import { OpMaterialGroupIM, OpMaterialGroupPM, OpMaterialGroupLM } from '@/model/operations/materialgroup.model';
import { defHttp } from '@/utils/http/axios';
import { formatToDateTime } from '@/utils/core/DateUtil';
import dayjs from 'dayjs';

const basicApi = '/operations/admin/materialgroup';

enum Api {
  LIST = basicApi + '/list',
  GET = basicApi + '/',
  ADD = basicApi,
  EDIT = basicApi,
  DEL_BATCH = basicApi + '/batch/',
  EXPORT = basicApi + '/export',
}

/** 查询资料分类列表 */
export const listOpMaterialGroupApi = (params?: OpMaterialGroupPM) =>
  defHttp.get<OpMaterialGroupLM>({ url: Api.LIST, params });

/** 查询资料分类详细 */
export const getOpMaterialGroupApi = (id: string) =>
  defHttp.get<OpMaterialGroupIM>({ url: Api.GET, params: id });

/** 新增资料分类 */
export const addOpMaterialGroupApi = (params: OpMaterialGroupIM) =>
  defHttp.post({ url: Api.ADD, params });

/** 修改资料分类 */
export const editOpMaterialGroupApi = (params: OpMaterialGroupIM) =>
  defHttp.put({ url: Api.EDIT, params });

/** 删除资料分类 */
export const delOpMaterialGroupApi = (ids: string | string[]) =>
  defHttp.delete({ url: Api.DEL_BATCH, params: ids.toString() });

/** 导出资料分类 */
export const exportOpMaterialGroupApi = async (params?: OpMaterialGroupPM) =>
  defHttp.export<any>(
    { url: Api.EXPORT, params: params },
    '资料分类_' + formatToDateTime(dayjs()) + '.xlsx',
  );
